You are not logged in Log in Join
You are here: Home » Members » 4AM Productions (Evan Simpson) » DTMLWiki » Inserting Objects and Expressions » wikipage_view

Log in
Name

Password

 
 
FrontPage » RevolutionaryProposals » Structured Zope Scripting »

Inserting Objects and Expressions

To render and insert a Zope object you use the caret (^) followed by the object name and optional arguments. It would look like so:

    ^myObj

This would be the direct equivilant of <dtml-var myObj>. The insertion statement is terminated either by a line break, or a ";" if you wanted to insert HTML or other objects on the same line.

To pass some arguments, it would look like this:

    ^myObj(arg=value, arg2=value)

If you wished to render an object indirectly (specify the name of the object in a string) you would type:

    ^_[objName]
or  
    ^_.getitem(objName)

The _ namespace object could be made implicit also leading to the possibility of calls like:

   ^DateTime("1/1/2001")

To render the result of an expression, put the expression in parens as in:

   ^(foo + bar)

To call a method and not render the results (ala <dtml-call>) use a bang "!" in place of the caret "^":

    !sql_wipe_db(key="*")

In order for this to work reliably, calls statements must occupy the entire line. This should improve readability anyhow.

To do formatting I propose simply using the Python formatting operator (%):

    ^(amount % "$%.2f")

Other special formatting could be handled by string functions or even methods of a resulting string like:

    ^str(name).capitalize()

or perhaps

    ^string.capitalize(name)

To handle missing/null values, a function could also be used.

    ^missing(optionalVar, "None")
    ^null(paymentDate, "No Payment Yet")